/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package racesuitefx.entities;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Wolfgang
 */
@Entity
@Table(name = "race")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Race.findAll", query = "SELECT r FROM Race r"),
    @NamedQuery(name = "Race.findByRaceId", query = "SELECT r FROM Race r WHERE r.raceId = :raceId"),
    @NamedQuery(name = "Race.findByActive", query = "SELECT r FROM Race r WHERE r.active = :active"),
    @NamedQuery(name = "Race.findByDate", query = "SELECT r FROM Race r WHERE r.date = :date"),
    @NamedQuery(name = "Race.findByName", query = "SELECT r FROM Race r WHERE r.name = :name"),
    @NamedQuery(name = "Race.findByPlace", query = "SELECT r FROM Race r WHERE r.place = :place")})
public class Race implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "raceId")
    @TableGenerator(name="TABLE_GEN", table="SEQUENCE_TABLE", pkColumnName="SEQ_NAME",
     valueColumnName="SEQ_COUNT", pkColumnValue="RACE_SEQ")
    @GeneratedValue(strategy=GenerationType.TABLE, generator="TABLE_GEN")
    private Integer raceId;
    @Column(name = "active")
    private String active;
    @Column(name = "date")
    @Temporal(TemporalType.DATE)
    private Date date;
    @Column(name = "name")
    private String name;
    @Column(name = "place")
    private String place;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "race", fetch = FetchType.LAZY)
    private Collection<Starter> starterCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "race")
    private Collection<Lap> lapCollection;

    public Race() {
    }
    public Race(String raceName){
        this.name = raceName;
    }

    public Race(Integer raceId) {
        this.raceId = raceId;
    }

    public Integer getRaceId() {
        return raceId;
    }

    public void setRaceId(Integer raceId) {
        this.raceId = raceId;
    }

    public String getActive() {
        return active;
    }

    public void setActive(String active) {
        this.active = active;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPlace() {
        return place;
    }

    public void setPlace(String place) {
        this.place = place;
    }

    @XmlTransient
    public Collection<Starter> getStarterCollection() {
        return starterCollection;
    }

    public void setStarterCollection(Collection<Starter> starterCollection) {
        this.starterCollection = starterCollection;
    }

    @XmlTransient
    public Collection<Lap> getLapCollection() {
        return lapCollection;
    }

    public void setLapCollection(Collection<Lap> lapCollection) {
        this.lapCollection = lapCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (raceId != null ? raceId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Race)) {
            return false;
        }
        Race other = (Race) object;
        if ((this.raceId == null && other.raceId != null) || (this.raceId != null && !this.raceId.equals(other.raceId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return this.getName();
    }
    
}
